The SpeakToMe program demonstrates how to use the Speech Synthesis Manager in a simple application. In addition to showing how to speak a string or a buffer of text, it exercises the API for selecting a voice and for changing the speaking rate and baseline pitch.
The About Dialog (see the ShowAboutMeDialog function) calls SpeakString to speak a simple string of text using the system default voice, speaking rate, and baseline pitch. This is the simplest and easiest way to add speech synthesis to an application.
The Files menu permits a buffer filled with randomly generated text to be spoken using the SpeakText API call. It also allows synthesis to be interrupted and resumed using PauseSpeechAt and ContinueSpeech. To halt synthesis, the files menu calls StopSpeech.
Unlike SpeakString, SpeakText and the other API calls made from the Files menu require a speech channel to be allocated. SpeakToMe initially allocates a speech channel (NewSpeechChannel) using the system default voice. The program allows users to change voices via the Voice menu and a function called ChangeVoice. The Voice menu presents a list of all voices currently available on the user's system. This list is built automatically at launch time by the InstallVoiceList function, which in turn calls CountVoices, GetIndVoice and GetVoiceDescription to obtain information about the voices.
Once a voice has been selected, SpeakToMe lets the user play with the speaking rate and baseline pitch of the voice via the Rate and Pitch menus. The Rate menu calls SetSpeechRate to increase or decrease the default speaking rate by 30%. It also allows the rate to be reset to the default for the active voice. Similarly, the Pitch menu calls SetSpeechPitch to raise or lower the pitch by half an octave and to reset the pitch to the default.
On exit, the program checks to see if speech is active by calling SpeechBusy. If synthesis
is occurring, it calls StopSpeech before deallocating the speech channel (DisposeSpeechChannel) and terminating.
For more information on the Apple's Speech Synthesis technology and API, see the Speech Manager chapter in the Sound volume of Inside Macintosh.